
self.buffers = null;

self.onmessage = function(e){

    self.buffers = e.data;
	
};

self.onaudioprocess = function (e) {

	var bufferData = null;
	var bufferArray = self.buffers;
	if (bufferArray != null && bufferArray.length > 0) bufferData = bufferArray.shift();

	if (bufferData == null) {
		for (var channel=0; channel<e.outputBuffers.length; channel++) {
			e.outputBuffers[channel].fill(0);
		}
		//console.log('GAP!');
		return;
	}
	
	for (var channel=0; channel<e.outputBuffers.length; channel++) {
		e.outputBuffers[channel].set(bufferData[channel]);
	}
	
	self.postMessage(bufferArray.length);
};
